﻿<%@ Page Title="" Language="C#" MasterPageFile="~/resumemanager/resume.master" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Import Namespace="TalentPools.Model" %>
<%@ Import Namespace="TalentPools.BLL" %>
<script runat="server">
    private string resumeId;

    public string ResumeId
    {
        get { return ViewState["resumeId"].ToString(); }
        set { ViewState["resumeId"] = value; }
    }
    protected void imgbtnnext_Click(object sender, ImageClickEventArgs e)
    {
        if (CreateRecord())
        {
            DataBind(ResumeId);
        }
    }
    private void DataBind(string resumeId)
    {
        List<record> list = new RecordManager().GetRecord(resumeId);
        dlWork.DataSource = list;
        dlWork.DataBind();
    }
    private bool CreateRecord()
    {
        record re = new record();
        re.resumeId = ResumeId;
        re.title = txtrename.Text.Trim();
        re.beginTime = Convert.ToDateTime(txtrebegintime.Text.Trim());
        re.endTime = Convert.ToDateTime(txtreendtime.Text.Trim());
        re.content = txtrecon.Text.Trim();
        re.details = txtredetails.Text.Trim();
        return new CreateresumeManager().creatRecord(re);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.txtrebegintime.Attributes.Add("ReadOnly", "true");
            this.txtreendtime.Attributes.Add("ReadOnly", "true");
            this.txtbtime.Attributes.Add("ReadOnly", "true");
            this.txtetime.Attributes.Add("ReadOnly", "true");
            if (Session["userid"] == null)
            {
                Response.Redirect("~/Default.aspx");
            }
            string resumeId = Request.QueryString["resumeId"];
            ResumeId = resumeId;
            if (resumeId == null || resumeId == "")
            {
                Response.Redirect("~/Default.aspx");
            }
            DataBind(ResumeId);
        }
    }

    protected void lbtnContinueWorkRecord_Click(object sender, EventArgs e)
    {
        if (CreateRecord())
        {
            txtrename.Text = "";
            txtrebegintime.Text = "";
            txtrecon.Text = "";
            txtredetails.Text = "";
            txtreendtime.Text = "";
            DataBind(ResumeId);
        }
    }

    protected void ibtnSaveR_Click(object sender, ImageClickEventArgs e)
    {
        if (SaveRecord(ViewState["recordId"].ToString()))
        {
            DataBind(ResumeId);
        }
    }
    private bool SaveRecord(string recordId)
    {
        record re = new record();
        re.title = txtTitle.Text.Trim();
        re.recordid = recordId;
        re.beginTime = Convert.ToDateTime(txtbtime.Text.Trim());
        re.endTime = Convert.ToDateTime(txtetime.Text.Trim());
        re.content = txtcon.Text.Trim();
        re.details = txtdetail.Text.Trim();
        return new alertResumeManager().updaterec(re);
    }

    protected void dlWork_EditCommand(object source, DataListCommandEventArgs e)
    {
        ViewState["recordId"] = dlWork.DataKeys[e.Item.ItemIndex];
        record re = new RecordManager().GetRecord(resumeId, ViewState["recordId"].ToString());
        txtTitle.Text = re.title;
        txtbtime.Text = re.beginTime.ToShortDateString();
        txtetime.Text = re.endTime.ToShortDateString();
        txtcon.Text = re.content;
        txtdetail.Text = re.details;
        ClientScript.RegisterStartupScript(typeof(string), "", "<scr" + "ipt" + ">edit();</sc" + "ript>");
    }

    protected void lbtnSaveCR_Click(object sender, EventArgs e)
    {
        if (SaveRecord(ViewState["recordId"].ToString()))
        {
            DataBind(ResumeId);
            ClientScript.RegisterStartupScript(typeof(string), "", "<scr" + "ipt" + ">edit1();</sc" + "ript>");
        }
    }

    protected void lbtnHl_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(typeof(string), "", "<scr" + "ipt" + ">edit1();</sc" + "ript>");
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        #add
        {
            display: block;
        }
        #update
        {
            display: none;
        }
    </style>
    <script type="text/javascript">
        function edit() {
            $("#add").css("display", "none");
            $("#update").css("display", "block");
        }
        function edit1() {
            $("#add").css("display", "block");
            $("#update").css("display", "none");
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:DataList ID="dlWork" runat="server" CssClass="tranningList" 
            OnEditCommand="dlWork_EditCommand" DataKeyField="recordid">
            <HeaderTemplate>
                <table class="tableMain" style="width: 100%">
                    <tr>
                        <td class="titleStyle" style="text-align: center; width: 20%;">
                            名称
                        </td>
                        <td class="valStyle" style="text-align: center; width: 20%;">
                            开始时间—结束时间
                        </td>
                        <td class="textStyle" style="text-align: center; width: 45%;">
                            内容
                        </td>
                        <td class="editStyle" style="width: 15%">
                        </td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td class="titleStyle" style="text-align: center; width: 20%;">
                        <%#Eval("title") %>
                    </td>
                    <td class="valStyle" style="text-align: center; width: 20%;">
                        <%# WebManager.BasePage.SetTimeFormat(Convert.ToDateTime(Eval("beginTime"))) %>—<%# WebManager.BasePage.SetTimeFormat(Convert.ToDateTime(Eval("endTime"))) %></td>
                    <td class="textStyle" style="text-align: center; width: 45%;">
                        <%#Eval("content") %>
                    </td>
                    <td class="editStyle" style="width: 15%">
                        <asp:LinkButton ID="lbtnEdit" runat="server" Text="编辑" CommandName="Edit"></asp:LinkButton>
                        <asp:LinkButton ID="lbtnDel" runat="server" Text="删除"></asp:LinkButton>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:DataList>
    </div>
    <div id="add">
        <br />
        <span style="height: 25px; font-family: 微软雅黑 宋体; font-size: 14px; text-align: left;">
            新增工作经历</span>
        <br />
        <br />
        <table class="tableMain">
            <tr>
                <td class="titleStyle">
                    名称:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtrename" runat="server" ValidationGroup="four" BorderStyle="None"
                        Width="195px"></asp:TextBox>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator21" runat="server" ControlToValidate="txtrename"
                        ErrorMessage="*必填" ValidationGroup="four" Display="Dynamic"></asp:RequiredFieldValidator>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    开始时间:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtrebegintime" runat="server" CssClass="Wdate" ValidationGroup="four"
                        BorderStyle="None" Width="195px"></asp:TextBox>
                    <asp:CalendarExtender TargetControlID="txtrebegintime" ID="CalendarExtender2" runat="server">
                    </asp:CalendarExtender>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator22" runat="server" ControlToValidate="txtrebegintime"
                        ErrorMessage="*必填" ValidationGroup="four" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    结束时间:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtreendtime" runat="server" CssClass="Wdate" ValidationGroup="four"
                        BorderStyle="None" Width="195px"></asp:TextBox>
                    <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtreendtime">
                    </asp:CalendarExtender>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator23" runat="server" ControlToValidate="txtreendtime"
                        ErrorMessage="*必填" ValidationGroup="four" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    工作内容:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtrecon" runat="server" ValidationGroup="four" BorderStyle="None"
                        Width="195px" MaxLength="20"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    详细描述:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtredetails" runat="server" ValidationGroup="four" BorderStyle="None"
                        Width="195px" Height="142px" MaxLength="500" TextMode="MultiLine"></asp:TextBox>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:ImageButton ID="imgbtnnext" runat="server" ImageUrl="~/img/create.gif" OnClick="imgbtnnext_Click"
                        ValidationGroup="four" />
                    <asp:LinkButton ID="lbtnContinueWorkRecord" runat="server" OnClick="lbtnContinueWorkRecord_Click">保存并继续添加工作经历</asp:LinkButton>
                    &nbsp;
                </td>
            </tr>
        </table>
    </div>
    <div id="update">
        <span style="width: 90%; height: 25px; font-family: 微软雅黑 宋体; font-size: 14px; color: #000;
            text-align: left;">修改工作经历</span>
        <table class="tableMain">
            <tr>
                <td class="titleStyle">
                    名称:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtTitle" runat="server" ValidationGroup="four" BorderStyle="None"
                        Width="195px"></asp:TextBox>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtTitle"
                        ErrorMessage="*必填" ValidationGroup="four" Display="Dynamic"></asp:RequiredFieldValidator>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    开始时间:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtbtime" runat="server" CssClass="Wdate" ValidationGroup="four"
                        BorderStyle="None" Width="195px"></asp:TextBox>
                    <asp:CalendarExtender TargetControlID="txtbtime" ID="CalendarExtender3" runat="server">
                    </asp:CalendarExtender>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtbtime"
                        ErrorMessage="*必填" ValidationGroup="four" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    结束时间:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtetime" runat="server" CssClass="Wdate" ValidationGroup="four"
                        BorderStyle="None" Width="195px"></asp:TextBox>
                    <asp:CalendarExtender TargetControlID="txtetime" ID="CalendarExtender4" runat="server">
                    </asp:CalendarExtender>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtetime"
                        ErrorMessage="*必填" ValidationGroup="four" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    工作内容:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtcon" runat="server" ValidationGroup="four" BorderStyle="None"
                        Width="195px" MaxLength="20"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    详细描述:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtdetail" runat="server" ValidationGroup="four" BorderStyle="None"
                        Width="195px" Height="142px" MaxLength="500" TextMode="MultiLine"></asp:TextBox>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:ImageButton ID="ibtnSaveR" runat="server" ImageUrl="~/img/create.gif" ValidationGroup="four"
                        OnClick="ibtnSaveR_Click" />
                    <asp:LinkButton ID="lbtnSaveCR" runat="server" OnClick="lbtnSaveCR_Click">保存并继续添加工作经历</asp:LinkButton>
                    &nbsp;
                    <asp:LinkButton ID="lbtnHl" runat="server" OnClick="lbtnHl_Click">忽略</asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
